﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Common;
using Persistence.Dao;
using Domain;
using Persistence;
namespace web.manage
{
    public partial class sendmessage_operate : System.Web.UI.Page
    {
        int id = DNTRequest.GetQueryInt("id", 0);
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (id > 0)
                {
                    SendMessage entity_SendMessage = Singleton<SendMessageDao>.Instance.GetModel(id);
                    if (entity_SendMessage != null)
                    {
                        ViewState["entity_SendMessage"] = entity_SendMessage;
                        txt_SendMessage_orderID.Value = entity_SendMessage.orderID;
                        txt_SendMessage_expressCorp.Value = entity_SendMessage.expressCorp;
                        txt_SendMessage_billNo.Value = entity_SendMessage.billNo;
                        txt_SendMessage_receiverName.Value = entity_SendMessage.receiverName;
                        txt_SendMessage_sendtime.Value = entity_SendMessage.sendtime.ToString();
                        txt_SendMessage_orderSchedule.Value = entity_SendMessage.orderSchedule;
                    }
                }
            }
        }
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            SendMessage entity_SendMessage = new SendMessage();
            if (id > 0 && ViewState["entity_SendMessage"] != null)
            {
                entity_SendMessage = (SendMessage)ViewState["entity_SendMessage"];
            }
            entity_SendMessage.orderID = txt_SendMessage_orderID.Value.Trim();
            entity_SendMessage.expressCorp = txt_SendMessage_expressCorp.Value.Trim();
            entity_SendMessage.billNo = txt_SendMessage_billNo.Value.Trim();
            entity_SendMessage.receiverName = txt_SendMessage_receiverName.Value.Trim();
            entity_SendMessage.sendtime = Utils.ObjectToDateTime(txt_SendMessage_sendtime.Value.Trim(), DateTime.Now);
            entity_SendMessage.orderSchedule = txt_SendMessage_orderSchedule.Value.Trim();
            bool bResult = false;
            if (id > 0)
            {
                bResult = Singleton<SendMessageDao>.Instance.Update(entity_SendMessage);
            }
            else
            {
                try
                {
                    Singleton<SendMessageDao>.Instance.Insert(entity_SendMessage);
                    bResult = true;
                }
                catch { }
            }
            if (bResult)
            {
                Message.alert("操作成功");
                txt_SendMessage_orderID.Value = "";
                txt_SendMessage_expressCorp.Value = "";
                txt_SendMessage_billNo.Value = "";
                txt_SendMessage_receiverName.Value = "";
                txt_SendMessage_sendtime.Value = "";
                txt_SendMessage_orderSchedule.Value = "";
            }
            else
            {
                Message.alert("操作失败，请检查您的数据");
            }
        }
    }
}
